package com.qfedu.stussm.controller;

import com.qfedu.stussm.dto.DeptDto;
import com.qfedu.stussm.service.intf.DeptService;
import com.qfedu.stussm.vo.DeptR;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @RequestMapping("api/stussm/insert.do")
    public DeptR insert(DeptDto dept) {
       return deptService.insert(dept);
    }

    @GetMapping("api/stussm/select.do")
    public PageBeanVo select(String name,int page,int limit){
        PageBeanVo select = deptService.select(name,page, limit);
     //   System.out.println("controller:"+name);
        return select;
    }

    @GetMapping("api/stussm/del.do")
    public DeptR del(Integer id){
        System.out.println(id);
        return deptService.del(id);
    }

    @PostMapping("api/stussm/update.do")
    public DeptR update(DeptDto dept){

        DeptR update = deptService.update(dept);
        System.out.println(dept);
        return update;
    }
    @PostMapping("api/stussm/delmany.do")
    public DeptR dele(Integer[] id) {
        System.out.println("ids:" + id);
        if (id == null) {
            return DeptR.fail();
        } else {
            for (Integer i : id) {
                System.out.println(i);
            }
            return deptService.dele(id);
        }
    }
    @GetMapping("api/stussm/deptEcharts.do")
    public R deptEcharts(){
        return deptService.deptEchartsSelect();
    }

    @GetMapping("api/stussm/download.do")
    public void download(HttpServletResponse response) throws IOException {
        deptService.download(response);
    }
    @PostMapping("api/stussm/upload.do")
    public R upload(MultipartFile file) throws IOException {
        System.out.println("controller"+file);
        return deptService.upload(file);
    }
}
